{include file='public/header' /}
</head>
<body style="padding: 10px;">
<form class="layui-form">
    <input type="hidden" name="id" value="{$data.item.id}">

    <div class="layui-form-item">
        <label class="layui-form-label">手机号</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="phone" value="{$data.item.phone}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">姓&nbsp;&nbsp;&nbsp;&nbsp;名</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="truename" value="{$data.item.truename}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">角&nbsp;&nbsp;&nbsp;&nbsp;色</label>
        <div class="layui-input-inline">
            <select name="gid">
                <option value=0></option>
                {volist name="data.groups" id="vo"}
                <option value="{$vo.gid}" {$vo.gid == $data.item.gid ? 'selected' : ''}>{$vo.title}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">密&nbsp;&nbsp;&nbsp;&nbsp;码</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" name="pwd">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">状&nbsp;&nbsp;&nbsp;&nbsp;态</label>
        <div class="layui-input-inline">
            <input type="checkbox" name="status" lay-skin="primary" title="禁用" value="1" {$data.item.status?'checked':''}>
        </div>
    </div>
</form>
<div class="layui-form-item">
    <div class="layui-input-block">
        <button class="layui-btn" onclick="save()">保存</button>
    </div>
</div>

<script type="text/javascript">
    layui.use(['layer','form'],function(){
        form = layui.form;
        layer = layui.layer;
        $ = layui.jquery;
    });

    // 保存管理员
    function save(){
        var id = parseInt($('input[name="id"]').val());
        var phone = $.trim($('input[name="phone"]').val());
        var pwd = $.trim($('input[name="pwd"]').val());
        var gid = $('select[name="gid"]').val();
        var truename = $.trim($('input[name="truename"]').val());
        //alert(isNaN(id));
        // if(username==''){
        //     layer.alert('请输入用户名',{icon:2});
        //     return;
        // }
        if(isNaN(id) && pwd==''){
            layer.alert('请输入密码',{icon:2});
            return;
        }
        if(gid==0){
            layer.alert('请选择角色',{icon:2});
            return;
        }
        if(truename==''){
            layer.alert('请输入姓名',{icon:2});
            return;
        }
        //.serialize()是将表单中的值序列化id=0&username=2&gid=1&pwd=2&truename=2
        $.post('__PUBLIC__/admin/admin/save',$('form').serialize(),function(res){
            console.log(res);
            if(res.code>0){
                layer.alert(res.msg,{icon:2});
            }else{
                layer.msg(res.msg);
                setTimeout(function(){parent.window.location.reload();},1000);
            }
        },'json');
    }

</script>
</body>
</html>